package com.css.fxfzxczh.org.repository.impl;

import com.css.fxfzxczh.org.entity.DivisionEntity;
import com.css.fxfzxczh.org.repository.BaseDivisionRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class BaseDivisionRepositoryImpl implements BaseDivisionRepository {

    @Autowired
    JdbcTemplate jdbcTemplate;

    @Override
    public List<DivisionEntity> findByIsValid(String isValid) {

        String sql = "select * from org_division where is_valid = '" + isValid+"\'";
        try {
            List<DivisionEntity> divisionEntities = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(DivisionEntity.class));
            return divisionEntities;
        }catch (EmptyResultDataAccessException e){
            return null;
        }
    }

    @Override
    public List<String> findDivisionNamesByDivisionId(String[] ids) {
        return null;
    }
}
